<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" id="input" />
    <input type="text" id="output" />
    <button id="copy">一键复制</button>
    <button id="paste">一键粘贴</button>

    <script>
      let str = 'Hello, world'
      const iptEle = document.querySelector('input')
      const optEle = document.querySelector('#output')
      iptEle.value = str

      const cpyBtn = document.querySelector('#copy')
      const patseBtn = document.querySelector('#paste')

      // clipboard 对象
      const clipboardObj = navigator.clipboard

      cpyBtn.addEventListener('click', async function () {
        iptEle.select()
        // const text = await clipboardObj.readText()
        // console.log(text)

        const text = await navigator.clipboard.readText()
        console.log(text)
      })

      patseBtn.addEventListener('click', function () {})
    </script>
  </body>
</html>
